package com.example.ruiji.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ruiji.common.BaseContext;
import com.example.ruiji.pojo.Orders;
import com.example.ruiji.pojo.R;
import com.example.ruiji.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("submit")
    public R<String> save(@RequestBody Orders orders)
    {
        orderService.savea(orders);
        return R.success("下单成功");
    }
@GetMapping("/userPage")
    public R<Page> pageR(Long page,Long pageSize)
{
Page<Orders> page1=new Page<>(page,pageSize);
//根据用户ID查询 当前的订单
    Long currentId = BaseContext.getCurrentId();
    LambdaQueryWrapper<Orders> queryWrapper=new LambdaQueryWrapper<>();
    queryWrapper.eq(Orders::getUserId,currentId);
     orderService.page(page1,queryWrapper);
    return R.success(page1);
}
    @GetMapping("/page")
    public R<Page> pageA(Long page,Long pageSize)
    {
        Page<Orders> page1=new Page<>(page,pageSize);
//根据用户ID查询 当前的订单

        orderService.page(page1);
        return R.success(page1);
    }
    @PutMapping
    public R<String> paison(@RequestBody Orders orders){
     //根据传来的ID 进行更新即可
        orderService.updateById(orders);
        return R.success("成功");
    }


}
